import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class LogEntry {
	private static final CommandType undoableCommandTypes[] = {
		CommandType.ADD,
		CommandType.DELETE,
		CommandType.CLEAR,
		CommandType.MARK,
		CommandType.UNMARK,
		CommandType.EDIT,
	};
	
	private static final String undoableCmdTypeString[] = {
		"add",
		"del",
		"clear",
		"mark",
		"unmark",
		"edit"
	};
	
	
	private DateTime timestamp;
	private String cmd;
	private CommandType cmdType;	
	private TaskList tasks_;
	
	//@author A0099655J
	public LogEntry(DateTime timestamp, String cmd, TaskList tasks) {
		this.timestamp = timestamp;
		this.cmd = cmd;
		this.tasks_ = tasks;
		for (int i=0; i<undoableCmdTypeString.length; i++) {
			if (undoableCmdTypeString[i].equalsIgnoreCase(cmd)) {
				cmdType = undoableCommandTypes[i];
			}
		}
	}
	
	//@author A0099655J
	public DateTime getTimestampAsDT() {
		return timestamp;
	}
	
	//@author A0099655J
	public String getTimestampAsString() {
		DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
		String timestamp_str = timestamp.toString(formatter);
		return timestamp_str;
	}
	
	//@author A0099655J
	public String getCmd() {
		return cmd;
	}
	
	//@author A0099655J
	public CommandType getCmdType() {
		return cmdType;
	}
	
	//@author A0099655J
	public int getNumTasks() {
		return tasks_.getNumTasks();
	}
	
	//@author A0099655J
	public TaskList getTasks() {
		return tasks_;
	}
	
	//@author A0099655J
	// for debugging purpose
	@Override
	public String toString() {
		DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
		String time = timestamp.toString(formatter);
		return time + cmd;
	}
}